<!---->
<template>
    <div class="page_petition">
        <common-header :title="'上访记录'" :showBack="true"></common-header>
        <div class="btn-save" @click="saveInfo">保存</div>
        <div class="pages-main" style="height: calc( 100vh - 45px)">
            <div class="item-info">
                <div class="item-item">
                    <datetime :min-year="1900" title="上访时间" placeholder="请选择上访时间" v-model="visitedtime1"></datetime>
                </div>
                <div class="item-item">
                    <x-input title="上访单位"  v-model="visitedorg"
                             placeholder="请输入上访单位">
                    </x-input>
                </div>
            </div>
            <group title="上访原因">
                <x-textarea :max="100" v-model="visitedreason" placeholder="请输入上访原因"></x-textarea>
            </group>
            <group title="安抚措施">
                <x-textarea :max="100" v-model="measures" placeholder="请输入安抚措施"></x-textarea>
            </group>
            <group class="hasnext">
                <x-switch title="是否还有意愿上访" v-model="hasnext"></x-switch>
            </group>
        </div>
    </div>
</template>

<script>
    import {XSwitch, Group, Cell, XInput, Datetime, XTextarea} from 'vux'
    import resident from '../../services/resident'
    export default {
        name: "petition",
        components: {
            XSwitch,
            Group,
            Cell,
            XInput,
            Datetime,
            XTextarea
        },
        data() {
            return {
                visitedid:this.$route.query.visitedid ? this.$route.query.visitedid: '',
                id:this.$route.query.id  ? this.$route.query.id: '',
                visitedtime1: this.$route.query.visitedtime ? this.$route.query.visitedtime : '',
                visitedorg:this.$route.query.visitedorg ? this.$route.query.visitedorg : '',
                visitedreason:this.$route.query.visitedreason ? this.$route.query.visitedreason : '',
                measures:this.$route.query.measures ? this.$route.query.measures : '',
                hasnext:this.$route.query.hasnext ? true : false,
            }
        },

        created() {

        },
        watch: {},
        methods: {
            saveInfo(){
                if (!this.visitedtime1) {
                    this.$vux.toast.show({
                        text: '请选择上访时间',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }
                if (!this.visitedorg) {
                    this.$vux.toast.show({
                        text: '请填写上访单位',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }
                if (!this.visitedreason) {
                    this.$vux.toast.show({
                        text: '请输入上访原因',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                } if (!this.measures) {
                    this.$vux.toast.show({
                        text: '请输入安抚措施',
                        type: 'text',
                        position: 'middle',
                    })
                    return;
                }

                let _param = this.$tools.invokeUAF('resident/saveVisitedInfo', {
                    id:this.id,
                    visitedid:this.visitedid,
                    visitedtime: this.visitedtime1 + ' ' + '00:00:00',
                    visitedorg:this.visitedorg,
                    visitedreason:this.visitedreason,
                    measures:this.measures,
                    hasnext:this.hasnext ? 1: 0,
                })
                resident.saveVisitedInfo(_param).then(res => {
                    let data = res.data.data;
                    this.visitedtime1 = this.visitedtime1.slice(0,10)
                })
            },
        },
    };
</script>

<style lang="less" rel="stylesheet/less" type="text/css">
.page_petition{

.hasnext{
.weui-cells{
    margin-top: 0!important;
}
}
}
</style>
